package com.maxlen.member.controller.reception;

import com.maxlen.common.utils.JwtUtils;
import com.maxlen.common.utils.R;
import com.maxlen.member.entity.MemberReceiveAddressEntity;
import com.maxlen.member.entity.dto.MemberReceiveAddressEntityDTO;
import com.maxlen.member.service.MemberReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member/reception/address")
public class MemberReceiveAddressReceptionController {

    @Autowired
    private MemberReceiveAddressService memberReceiveAddressService;

    /**
     * 将指定 id 的记录设置为默认地址
     * @param id
     * @param token 用户信息
     * @return
     */
    @GetMapping("/setDefaultStatus")
    public R setDefaultStatus(@RequestParam String id, @RequestParam String token){
        return memberReceiveAddressService.setDefaultStatus(id, token);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/deleteAddress/{id}")
    public R deleteAddress(@PathVariable String id){
        boolean remove = memberReceiveAddressService.removeById(id);
        if(remove){
            return R.ok();
        }else{
            return R.error();
        }
    }

    /**
     * 更新收货地址
     * @param memberReceiveAddressEntityDTO
     * @return
     */
    @PostMapping("/updateAddress")
    public R updateAddress(@RequestBody MemberReceiveAddressEntityDTO memberReceiveAddressEntityDTO){
        return memberReceiveAddressService.updateAddress(memberReceiveAddressEntityDTO);
    }

    /**
     * 添加收货地址
     * @param memberReceiveAddressEntityDTO
     * @return
     */
    @PostMapping("/addAddress")
    public R addAddress(@RequestBody MemberReceiveAddressEntityDTO memberReceiveAddressEntityDTO){
        return memberReceiveAddressService.addAddress(memberReceiveAddressEntityDTO);
    }

    /**
     * 根据 id 获取详情信息
     * @param addressId
     * @return
     */
    @GetMapping("/infoAddress/{addressId}")
    public R infoAddress(@PathVariable String addressId){
        MemberReceiveAddressEntityDTO memberReceiveAddressEntityDTO = memberReceiveAddressService.infoAddress(addressId);
        return R.ok().setData(memberReceiveAddressEntityDTO);
    }

}
